package cn.tedu.myioc2;

import cn.tedu.myioc.Bean;

import java.util.*;

public class MyIOC {
    private List<Bean> list = new ArrayList<>();
    private Map<String, Object> map = new HashMap<>();

    public MyIOC() throws Exception {
        Bean b1 = new Bean("user", "cn.tedu.myioc2.User");
        Bean b2 = new Bean("hello", "cn.tedu.myioc2.Hello");
        Collections.addAll(list, b1, b2);

        creatObj();
    }
    public void creatObj() throws Exception {
        for (Bean bean : list){
            String k = bean.getName();
            Object v = Class.forName(bean.getPath()).newInstance();
            map.put(k,v);
        }
    }
    public Object getBean(String key){
        return map.get(key);
    }
}
